/*
 * trafficLight.fx
 *
 * Created on 23-dic-2009, 21:17:43
 */

package ProgramSamples;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.ToggleGroup;
import javafx.scene.shape.Circle;
import javafx.scene.paint.Color;
import javafx.scene.paint.RadialGradient;
import javafx.scene.paint.Stop;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.control.RadioButton;
import javafx.scene.layout.Tile;

def group = ToggleGroup{};
def choiceText = ["STOP", "READY", "GO"];
def colors = ["RED", "GOLD", "GREEN"];

def choices = for (text in choiceText){
    RadioButton{
            toggleGroup: group
            text: text
    }//RadioButton
}
def lights = for (color in colors){
    Circle {
        centerX: 12
        centerY: 12
        radius: 12
        stroke: Color.DARKGRAY
        fill: bind RadialGradient {
            centerX: 8,
            centerY: 8,
            radius: 12,
            proportional: false
            stops: [
                Stop {offset: 0.0 color: Color.WHITE},
                Stop {offset: 1.0 color:
                        if (choices[indexof color].selected)
                              then Color.web(color)
                              else Color.GRAY
                }//Stop
            ]
        }//RadialGradient
    }//Circle
}
Stage {
    title: "Traffic lights"
    scene: Scene{
	width: 210
        height: 90

        content:

                    Tile {
                          columns: 2
                          rows: 3
                          vgap: 5
                          content: for (i in [0..2])
                             [choices[i], lights[i]]
                     }//Tile
        /*
        content:
             HBox{ spacing: 20
                content:[
                   VBox{ spacing: 10
                         content: choices
                   }
                   HBox{ spacing: 15 content: lights translateY: 25}
                ]
             }//HBox
        */
     } //Scene
}//Stage